<?php
class SysGroupAction extends CommonAction {

    protected $_str_model           = 'SysGroup';
    protected $_arr_search          = array(
                                            'group_id'        => array('EQ', '?', 'int'),
                                            'name'            => array('LIKE', '%?%', 'str'),
                                            'remark'          => array('LIKE', '%?%', 'str'),
                                            'status'          => array('EQ', '?', 'int'),
                                      );
                                      
    /**
     * Set params
     * global settings, for index, edit, add
     *
     * @param  void
     * @return void
     * @author andy
     */
    public function set_params() {

        $this->assign('str_role_tree_html', User::get_role_tree_html());
    }
    
    /**
     * Set params edit
     * 
     * @param  void
     * @return void
     * @author andy
     */
    public function set_params_edit() {
        
        $arr_info       = $this->get('arr_info');
        $arr_group_name = explode('_', $arr_info['name']);
        $this->assign('str_role_tree_html', User::get_role_tree_html(explode(',', $arr_info['role_ids'])));
        $this->assign('str_department', $arr_group_name[0]);
        $this->assign('str_group_name', implode('_', array_slice($arr_group_name, 1)));
    }
    
    /**
     * Before do action
     * for edit, add
     * 
     * @param  void
     * @return void
     * @author andy
     */
    public function before_do_action() {

        set_post('role_ids', implode(',', $this->_post('role_ids')));
        set_post('name', $this->_post('department') . '_' . $this->_post('name'));
    }
}